using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UI_Tips : WindowRoot
{
    private Text mTipTxt;
    protected Image mTipImgBg;
    private Animator mAnim;
    private readonly Queue<string> mTipsQueue = new Queue<string>();
    private bool mShowTips = false;

    private void Awake()
    {
        mAnim = GetComponent<Animator>();
        mTipImgBg = transform.Find("IMG_BGTips").GetComponent<Image>();
        mTipTxt =  mTipImgBg.transform.Find("TXT_Tips").GetComponent<Text>();
        mTipImgBg.gameObject.SetActive(false);
    }

    public override void InitWindow()
    {
        base.InitWindow();
        mTipTxt.text = string.Empty;
        mTipsQueue.Clear();
    }

    public void AddTips(string tip)
    {
        if (!string.IsNullOrEmpty(tip))
        {
            mTipsQueue.Enqueue(tip);
        }
    }

    private void Update()
    {
        if (mTipsQueue.Count > 0 && !mShowTips)
        {
            mShowTips = true;
            mTipImgBg.gameObject.SetActive(true);
            string tips  = mTipsQueue.Dequeue();
            mTipTxt.text = tips;
            mTipImgBg.GetComponent<RectTransform>().sizeDelta = new Vector2(35 * tips.Length, 80);
            mAnim.Play("TipsWnd",0,0);
        }
    }


    public void AniPlayDone()
    {
        mShowTips = false;
        mTipImgBg.gameObject.SetActive(false);
    }

}
